<template>
  <!-- 栅格第一行 -->
  <el-row :gutter="10" class="top">
    <el-col :span="6">
      <div class="grid-content ep-bg-purple">
        <img
          src="../../../assets/images/03数据中心_slices/juxingkuang04.png"
          class="bg"
        />
        <img
          src="../../../assets/images/03数据中心_slices/icon10.png"
          alt=""
          class="iconimg"
        />
        <p>今日成交额</p>
        <span>较昨日<em style="color: #f26060">+2.13%</em></span>
        <i>97831</i>
      </div>
    </el-col>
    <el-col :span="6">
      <div class="grid-content ep-bg-purple">
        <img
          src="../../../assets/images/03数据中心_slices/juxing06.png"
          class="bg"
        />
        <img
          src="../../../assets/images/03数据中心_slices/icon11.png"
          alt=""
          class="iconimg"
        />
        <p>今日订单量</p>
        <span>较昨日<em style="color: #9fc174">-5.54%</em></span>
        <i>56</i>
      </div>
    </el-col>
    <el-col :span="6">
      <div class="grid-content ep-bg-purple">
        <img
          src="../../../assets/images/03数据中心_slices/juxing07.png"
          class="bg"
        />
        <img
          src="../../../assets/images/03数据中心_slices/icon12.png"
          alt=""
          class="iconimg"
        />
        <p>今日访客量</p>
        <span>较昨日<em style="color: #f26060">+8.79%</em></span>
        <i>4823</i>
      </div>
    </el-col>
    <el-col :span="6">
      <div class="grid-content ep-bg-purple">
        <img
          src="../../../assets/images/03数据中心_slices/juxing08.png"
          class="bg"
        />
        <img
          src="../../../assets/images/03数据中心_slices/icon13.png"
          alt=""
          class="iconimg"
        />
        <p>代付款订单</p>
        <span>较昨日<em style="color: #9fc174">+2.13%</em></span>
        <i>12</i>
      </div>
    </el-col>
  </el-row>
  <!-- 栅格第二行 -->
  <el-row :gutter="10" class="mid">
    <!-- 折线图 -->
    <el-col :span="24">
      <div class="grid-content ep-bg-purple" id="main"></div>
    </el-col>
  </el-row>
  <!-- 栅格第三行 -->
  <el-row :gutter="10" class="bottom">
    <el-col :span="13">
      <div class="grid-content ep-bg-purple tab">
        <p>产品销量排行</p>
        <el-table :data="tableData" border style="width: 100%">
          <el-table-column prop="num" label="序号" />
          <el-table-column prop="goods" label="商品">
            <template #default="scope">
              <div style="display: flex; align-items: center">
                <img :src="scope.row.url" alt="" />
                <div>{{ scope.row.goods }}</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="sale" label="销量" />
          <el-table-column prop="amount" label="成交金额" />
        </el-table>
      </div>
    </el-col>
    <el-col :span="11">
      <!-- 饼状图 -->
      <div class="grid-content ep-bg-purple" id="pie" />
    </el-col>
  </el-row>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted } from "vue";
import * as echarts from "echarts";

export default defineComponent({
  setup() {
    onMounted(() => {
      init1();
      init2();
    });
    //折线图
    const init1 = () => {
      const main = document.getElementById("main");
      // eslint-disable-next-line
      let myChart: any;
      if (main) {
        myChart = echarts.init(main);
        myChart.setOption({
          title: {
            text: "成交金额 2022.05",
            padding: 20,
          },
          xAxis: {
            type: "category",
            boundaryGap: false,
            data: [
              "01",
              "02",
              "04",
              "06",
              "08",
              "10",
              "12",
              "14",
              "16",
              "18",
              "20",
              "22",
              "24",
              "26",
              "28",
              "30",
            ],
          },
          yAxis: {
            type: "value",
          },
          series: [
            {
              data: [
                13453, 16345, 18455, 24236, 54565, 24450, 19856, 38879, 49686,
                78473, 47839, 98493, 85938, 92458, 79385, 49768,
              ],
              type: "line",
              smooth: true,
              areaStyle: {
                color: "#FFDB92",
              },
            },
          ],
        });
      }

      window.addEventListener("resize", () => {
        myChart.resize();
      });
    };
    //饼状图
    const init2 = () => {
      const pie = document.getElementById("pie");
      // eslint-disable-next-line
      let myChart: any;
      if (pie) {
        myChart = echarts.init(pie);
        myChart.setOption({
          title: {
            text: "品牌销售额占比",
          },
          tooltip: {
            trigger: "item",
          },
          legend: {
            orient: "horizontal",
            bottom: "bottom",
          },
          color: ["#C4DE9B", "#FFDB92 ", "#A5D1FF", "#FFA79C "],

          series: [
            {
              type: "pie",
              radius: "70%",
              label: {
                formatter: "{d}%",
              },
              data: [
                { value: 1440, name: "PPSU奶瓶绿色" },
                { value: 720, name: "PPSU奶瓶黄色" },
                { value: 360, name: "PPSU奶瓶蓝色" },
                { value: 1080, name: "PPSU奶瓶粉色" },
              ],

              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: "rgba(0, 0, 0, 0.5)",
                },
              },
            },
          ],
        });
      }
    };
    //表格数据
    const tableData = [
      {
        num: "01",
        goods: "PPSU奶瓶绿色",
        url: require("../../../assets/images/03数据中心_slices/tupian01.png"),
        sale: "3481",
        amount: "97831",
      },
      {
        num: "02",
        goods: "PPSU奶瓶粉色",
        url: require("../../../assets/images/03数据中心_slices/tupian02.png"),
        sale: "3150",
        amount: "88515",
      },
      {
        num: "03",
        goods: "PPSU奶瓶黄色",
        url: require("../../../assets/images/03数据中心_slices/tupian03.png"),
        sale: "2975",
        amount: "83598",
      },
      {
        num: "04",
        goods: "PPSU奶瓶蓝色",
        url: require("../../../assets/images/03数据中心_slices/tupian04.png"),
        sale: "2745",
        amount: "77135",
      },
    ];
    return { tableData };
  },
});
</script>

<style lang="less" scoped>
.top {
  height: 160px;
  // background-color: aquamarine;
  /deep/.grid-content {
    height: 160px;
    // background-color: #fff;
    // border-radius: 10px;
    position: relative;
    .bg {
      width: 100%;
      height: 160px;
    }
    .iconimg {
      position: absolute;
      width: 79px;
      height: 96px;
      top: 37px;
      right: 38px;
    }
    p {
      font-size: 22px;
      font-weight: 500;
      position: absolute;
      top: 26px;
      left: 31px;
    }
    span {
      font-size: 23px;
      font-weight: 500;
      position: absolute;
      bottom: 12px;
      left: 32px;
    }
    i {
      font-size: 45px;
      font-weight: 500;
      position: absolute;
      bottom: 51px;
      left: 32px;
    }
  }
}
.mid {
  height: 386px;
  // background-color: lightblue;
  margin-top: 20px;
  /deep/.grid-content {
    height: 386px;
    background-color: #fff;
    border-radius: 10px;
  }
}
.bottom {
  height: 335px;
  margin-top: 20px;
  /deep/.grid-content {
    height: 335px;
    background-color: #fff;
    border-radius: 10px;
  }
  .tab {
    padding: 50px 10px 10px;
    position: relative;
    text-align: center;
    // height: 260;
    p {
      font-size: 19px;
      color: #333;
      font-family: MicrosoftYaHei;
      font-weight: 700;
      position: absolute;
      top: 6px;
      left: 10px;
    }
    img {
      width: 32px;
      height: 32px;
      margin-right: 10px;
    }
  }
}
/deep/.cell {
  text-align: center;
}
</style>
